package com.neuedu.api.usestring;

/**
 * @author 金山
 * 项目：javase
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/10/249:28
 */
public class MyStringBuffer {

    public static void main(String[] args) {

        //创建对象
        StringBuffer sbuffer = new StringBuffer();   // 容器的空间  长度 16 byte values[]
        // StringBuffer sbuffer = new StringBuffer(30);  // 容器的空间  长度 30   new byte[30]
        // StringBuffer sbuffer = new StringBuffer("hello buffer"); //容器的空间    如果字符串很长 超过Integer.max? Integer.max:  "字符串的长度" + 16
        StringBuffer sbuffer2 = new StringBuffer(sbuffer); //容器的空间    如果字符串很长 超过Integer.max? Integer.max:  "字符串的长度" + 16



        //sbuffer 容器的长度
        System.out.println("sbuffer.capacity() = " + sbuffer.capacity());  //16 +12
        System.out.println("sbuffer.length() = " + sbuffer.length());  // 0

        sbuffer.append("hello"); //
        sbuffer.append("0123456789abcdef    ");
        System.out.println("sbuffer.capacity() = " + sbuffer.capacity());  //34
        System.out.println("sbuffer.length() = " + sbuffer.length());  // 25



        StringBuffer buffer1 = new StringBuffer();

        buffer1.append("abcdef").append(100).append(3.14);

        System.out.println("buffer1 = " + buffer1);



        //insert
        StringBuffer buffer2 = new StringBuffer("0123456789");
        System.out.println("buffer2 before insert = " + buffer2);
        buffer2.insert(2,"abc");
        System.out.println("buffer2 after insert = " + buffer2);


        StringBuffer buffer3 = new StringBuffer("0123456789");
        System.out.println("buffer3 = " + buffer3);
        System.out.println("buffer3.deleteCharAt(4) = " + buffer3.deleteCharAt(4));
        System.out.println("buffer3.delete(1,2) = " + buffer3.delete(1,2)); // [1,2)


        System.out.println("\r\n\r\n");
        StringBuffer buffer4 = new StringBuffer("abcdef");
        for (int i = 0; i < buffer4.length(); i++) {
            char charAtIndex = buffer4.charAt(i);
            int codePointAtIndex = buffer4.codePointAt(i);

            System.out.printf("charAtIndex = %s ,codePointAtIndex:%d \r\n" , charAtIndex,codePointAtIndex);
        }



        //indexOf  lastIndexOf ......
        // buffer4.subSequence()



    }
}
